package com.itlaobing.dev;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * 1、通过继承javax.servlet.GenericServlet类来开发一个Servlet类(servlet-class)
 * 2、继承抽象类GenericServlet只需要实现抽象的service方法
 * 3、另外需要注意GenericServlet类中还额外定义了其它方法(除了在javax.servlet.Servlet接口中定义的5个方法外)
 */
public class UniversalServlet extends GenericServlet {

	private static final long serialVersionUID = -6008930033216084982L;

	@Override
	public void service(ServletRequest req , ServletResponse resp ) 
			throws ServletException, IOException {
		
		// 通过响应对象"告知"浏览器本次发送的内容是什么类型、什么编码
		resp.setContentType( "text/html;charset=UTF-8" );
		
		// 获得字符打印流
		PrintWriter out = resp.getWriter();
		
		// 打印字符
		out.println( "<html>" );
		out.println( "<head>" );
		out.println( "<title>Universal</title>" );
		// 指定href时按照 "/applicationPath/resourcePath" 方式指定，比如 "/core/styles/universal.css"
		out.println( "<link rel='stylesheet' href='/core/styles/universal.css'>" );
		out.println( "</head>" );
		
		out.println( "<body>" );
		
		for (int i = 0; i < 5; i++) {
			out.println( "<div class='wrapper'>" );
			out.println( i );
			out.println( "</div>" );
		}
		
		out.println( "</body>" );
		
		out.println( "</html>" );
		
	}

}
